import http from '@/utils/request'
import { LoginMessage, RootThunkAction } from '@/types/store'
import { Token, ApiResponse } from '@/types/data'
import { setToken } from '@/utils/storage'
// 手机登录保存token
export const getLogin = (val: LoginMessage): RootThunkAction => {
  return async (dispatch) => {
    const res = await http.post<ApiResponse<Token>>('/authorizations', val)
    // 1 将值保存在store中
    dispatch({
      type: 'SETTOKEN',
      token: res.data.data
    })
    // 2 将值保存在本地
    setToken(res.data.data)
  }
}
// 手机验证码请求
export const SendMessage = (mobile: string) => {
  return async () => {
    await http({
      method: 'GET',
      url: `/sms/codes/${mobile}`
    })
  }
}
